module ("background", package.seeall);

function Background()
     local bg = display.newImage("Assets/Background.png");
     drawLine = 0;
     drawLines = display.newGroup();

     function bg:BgPosition()

         self.y = display.contentHeight/2 ;

     end

     local function LineCollision(event)
         if(event.other.name == "rope")then
             display.remove(event.other);
             event.other = nil;
         end
     end
     local function DrawLine(event)


         if(event.phase == "began")then
             initX = event.x;
             initY = event.y;

         elseif(event.phase == "moved")then
             drawLine = display.newLine(initX, initY, event.x, event.y);
             physics.addBody(drawLine);
             drawLine.bodyType = "static";
             drawLine.isSensor = true;
             drawLine:addEventListener("collision", LineCollision);
             drawLine.width = 5;
             drawLines:insert(drawLine);

         elseif(event.phase == "ended")then
             display.remove(drawLines);
             drawLines = nil;
             drawLines = display.newGroup();
         end

     end
    bg:addEventListener("touch", DrawLine);
    return bg
end
